/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * tes.java
 *
 * Created on May 3, 2011, 3:09:00 PM
 */

package gitbox;

import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import java.awt.TextArea;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Lenovo
 */
public class tes extends javax.swing.JFrame {
    static ConcurrentHashMap<String, Integer> ServerStatus = null;
    static ConcurrentHashMap<String, Integer> BeforeStatus = null;
    static ConcurrentHashMap<String, Integer> NowStatus = null;
    
    /** Creates new form tes */
    public tes() {
        initComponents();
        ServerStatus = new ConcurrentHashMap<String, Integer>();
        BeforeStatus = new ConcurrentHashMap<String, Integer>();
        NowStatus = new ConcurrentHashMap<String, Integer>();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gitbox.GitBoxApp.class).getContext().getResourceMap(tes.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jTextField2.setName("jTextField2"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2))
                            .addComponent(jTextField1)
                            .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("Add");
        String namafile = jTextField1.getText();
        Integer nilainya = 0, temp;
        nilainya = Integer.parseInt(jTextField2.getText());
        //if (NowStatus.get(namafile)==null)
            NowStatus.put(namafile, nilainya);
        //else
        {
            //temp = NowStatus.get(namafile);
            //if (temp < nilainya)
            {
                //NowStatus.remove(namafile);
                //NowStatus.put(namafile, nilainya);
                //BeforeStatus.put(namafile, nilainya);
            }
        }
        update();
}//GEN-LAST:event_jButton1MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        // TODO add your handling code here:
        jTextArea1.setText("Delete");
        String namafile = jTextField1.getText();
        NowStatus.remove(namafile);
        update();
    }//GEN-LAST:event_jButton2MouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new tes().setVisible(true);
            }
        });
    }

    private void update()
    {
        MapDifference<String, Integer> mapDiff = Maps.difference(BeforeStatus, NowStatus);
        Integer nilainya;
        jTextArea1.setText("Yang sebelumnya ada dan sekarang ada juga : ");
        for (String key : mapDiff.entriesInCommon().keySet())
        {
            nilainya = mapDiff.entriesInCommon().get(key);
            jTextArea1.setText(jTextArea1.getText()+"\n- "+key+", nilainya = "+nilainya);
        }
        jTextArea1.setText(jTextArea1.getText()+"\nYang baru di-delete : ");
        for (String key : mapDiff.entriesOnlyOnLeft().keySet())
        {
            nilainya = mapDiff.entriesOnlyOnLeft().get(key);
            jTextArea1.setText(jTextArea1.getText()+"\n- "+key+", nilainya = "+nilainya);
            BeforeStatus.remove(key);
        }
        jTextArea1.setText(jTextArea1.getText()+"\nYang baru di-tambah : ");
        for (String key : mapDiff.entriesOnlyOnRight().keySet())
        {
            nilainya = mapDiff.entriesOnlyOnRight().get(key);
            jTextArea1.setText(jTextArea1.getText()+"\n- "+key+", nilainya = "+nilainya);
            BeforeStatus.put(key, nilainya);
        }
        jTextArea1.setText(jTextArea1.getText()+"\nYang beda gan : ");
        for (String key : mapDiff.entriesDiffering().keySet())
        {
            MapDifference.ValueDifference<Integer> beda = mapDiff.entriesDiffering().get(key);
            jTextArea1.setText(jTextArea1.getText()+"\n- "+key+", nilai awalnya = "+beda.leftValue()+", nilai yg dimasukkin = "+beda.rightValue());
            if (beda.leftValue()<beda.rightValue())
                BeforeStatus.put(key, beda.rightValue());
            else
                BeforeStatus.put(key, beda.leftValue());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables

}
